package guoanmaker.operator.business.service;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import guoanmaker.operator.business.dao.OperatorCommodityDao;
import guoanmaker.operator.business.model.MessageType;
import guoanmaker.operator.business.model.OperatorCity;
import guoanmaker.operator.business.model.OperatorRefuseRecord;
import guoanmaker.operator.business.model.OperatorRefuselist;
import guoanmaker.operator.business.model.OperatorUser;
import guoanmaker.operator.business.model.ProvideCity;
import guoanmaker.operator.business.model.ProvideCommodity;
import guoanmaker.operator.business.model.ProvideCommodityServiceRange;
import guoanmaker.operator.business.model.ProviderBusiness;
import guoanmaker.operator.business.model.ReturnResult;
import guoanmaker.operator.business.modelnobind.CommodityRo;
import guoanmaker.operator.business.modelnobind.OperatorCommodityRo;
import guoanmaker.operator.business.repository.MessageTypeRepository;
import guoanmaker.operator.business.repository.OperatorCityRepository;
import guoanmaker.operator.business.repository.OperatorRefuseRecordRepository;
import guoanmaker.operator.business.repository.OperatorRefuselistRepository;
import guoanmaker.operator.business.repository.OperatorUserRepository;
import guoanmaker.operator.business.repository.ProvideCityRepository;
import guoanmaker.operator.business.repository.ProvideCommodityRepository;
import guoanmaker.operator.business.repository.ProvideCommodityServiceRangeRepository;
import guoanmaker.operator.business.repository.ProviderBusinessRepository;
import guoanmaker.operator.helper.common.util.StringUtil;

@Service
public class CommodityManageService {

	@Autowired
	private   ProvideCommodityRepository provideCommodityRepository;
	
	@Autowired
	private   OperatorCommodityDao  operatorCommodityDao;
	
	@Autowired
	private  OperatorRefuselistRepository  operatorRefuselistRepository;
	
	@Autowired
	private  OperatorRefuseRecordRepository  operatorRefuseRecordRepository;
	
	@Autowired
	private OperatorUserRepository  operatorUserRepository;
	
	@Autowired  
	private  HttpServletRequest request;
	
	@Autowired
	private ProvideCommodityServiceRangeRepository  provideCommodityServiceRangeRepository;
	@Autowired
	private ProvideCityRepository provideCityRepository;
	
	@Autowired
    private	 ProviderBusinessRepository  providerBusinessRepository;
	@Autowired
	private OperatorCityRepository operatorCityRepository;
	
	@Autowired
	private MessageTypeRepository  messageTypeRepository;

	@Autowired
	private EntityManager entityManager;
	
	public  Map<String, Object>   selectcommdityInfos(Integer page,Integer size,Integer status){
		

		return  operatorCommodityDao.selectCommodityNoCondition(page, size, status);
	}
	
	@Transactional
	public Workbook   exportCommdityInfos(String  ids){
		
		Workbook wb = new HSSFWorkbook();
		Sheet sheet = wb.createSheet("商品信息");
		Row header = sheet.createRow(0);
		header.createCell(0).setCellValue("商品名称");
		header.createCell(1).setCellValue("价格");
		header.createCell(2).setCellValue("种类");
		header.createCell(3).setCellValue("申请店铺");
		header.createCell(4).setCellValue("申请时间");
	    List<ProvideCommodity> list=provideCommodityRepository.findAll(); 	
	    ProvideCommodity provideCommodity=new ProvideCommodity();
	    String[]  pids=ids.split(",");
		for (int i = 0; i < list.size(); i++) {
			provideCommodity=list.get(i);
			for (int j = 0; j < pids.length; j++) {
				String id=pids[j];
				if(id.equals(provideCommodity.getId())){
					Row dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
					dataRow.createCell(0).setCellValue(provideCommodity.getCommodityName()!=null?provideCommodity.getCommodityName():"");
					dataRow.createCell(1).setCellValue(provideCommodity.getCommodityPrice()!=null?provideCommodity.getCommodityPrice():0);
					dataRow.createCell(2).setCellValue(provideCommodity.getServiceType().getServerName()!=null?provideCommodity.getServiceType().getServerName():"");
					dataRow.createCell(3).setCellValue(provideCommodity.getProviderBusiness().getBusinessName()!=null?provideCommodity.getProviderBusiness().getBusinessName():"");
					dataRow.createCell(4).setCellValue(provideCommodity.getCreateTime()!=null?provideCommodity.getCreateTime():null);
				}
			}
		}
		return  wb;
	}
	
	public Workbook   exportAllCommdityInfos(String starttime ,String endtime){
		Workbook wb = new HSSFWorkbook();
		Sheet sheet = wb.createSheet("商品信息");
		Row header = sheet.createRow(0);
		header.createCell(0).setCellValue("商品编号");
		header.createCell(1).setCellValue("商品名称");
		header.createCell(2).setCellValue("价格（元）");
		header.createCell(3).setCellValue("种类");
		header.createCell(4).setCellValue("销量");
		header.createCell(5).setCellValue("企业名称");
		header.createCell(6).setCellValue("申请店铺");
		header.createCell(7).setCellValue("上架时间");
		List<OperatorCommodityRo>  list=operatorCommodityDao.selectallCommodity(starttime,endtime); 
		if(list.size()>0){
			OperatorCommodityRo provideCommodity=new OperatorCommodityRo();
			for (int i = 0; i < list.size(); i++) {
				        provideCommodity=list.get(i);
						Row dataRow = sheet.createRow(sheet.getLastRowNum() + 1);
						dataRow.createCell(0).setCellValue(provideCommodity.getCommodityCode()!=null?provideCommodity.getCommodityCode():0);
						dataRow.createCell(1).setCellValue(provideCommodity.getCommodityName()!=null?provideCommodity.getCommodityName():"");
						dataRow.createCell(2).setCellValue(provideCommodity.getFinalPrice()!=null?provideCommodity.getFinalPrice():0);
						dataRow.createCell(3).setCellValue(provideCommodity.getServerName()!=null?provideCommodity.getServerName():"");
						dataRow.createCell(4).setCellValue(provideCommodity.getSalesVolume()!=null?provideCommodity.getSalesVolume():0);
						dataRow.createCell(5).setCellValue(provideCommodity.getCompanyName()!=null?provideCommodity.getCompanyName():"");
						dataRow.createCell(6).setCellValue(provideCommodity.getBusinessName()!=null?provideCommodity.getBusinessName():"");
						if(provideCommodity.getReleaseTime()!=null&&!provideCommodity.getReleaseTime().equals("")){
							SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
					    	String ss=	sdf.format(provideCommodity.getReleaseTime()); 
							dataRow.createCell(7).setCellValue(ss);
						}else{
							dataRow.createCell(7).setCellValue("");
						}
			}
		}
		return  wb;
	}
	
	
/*	public  Map<String, Object>   multiConditionCommditys(Integer page,Integer size,Integer status,String category,Double startPrice,Double endPrice,String commdittyName,String busname){
		
		return   operatorCommodityDao.selectCommodity(page, size, status, category, startPrice, endPrice, commdittyName, busname);
	}*/
public  Map<String, Object> multiConditionCommditys (Integer page,Integer size,Integer status,String category,Double startPrice,Double endPrice,String commdittyName,String busname,String commodityCode) {
		
	
		return operatorCommodityDao.selectCommodity(page, size, status, category, startPrice, endPrice, commdittyName, busname,commodityCode);
	}
	
public ProvideCommodity selectBycommdityinfo(String id) {
	
	ProvideCommodity commodity=provideCommodityRepository.findOne(id);
	if(commodity!=null){
		if(commodity.getProviderBusiness()!=null){
			commodity.getProviderBusiness().setPersonalUser(null);
			commodity.getProviderBusiness().setProvideShop(null);
		}
		if(commodity.getServiceRange()!=null){
			List<ProvideCommodityServiceRange> serviceRange=commodity.getServiceRange();
			if(serviceRange.size()>0){
				for(int i=0;i<serviceRange.size();i++){
					serviceRange.get(i).setCommodity(null);
				}
			}
			commodity.setServiceRange(serviceRange);
		}
		
		commodity.setOrderforms(null);
	}
	return commodity;
}
/*public CommodityRo selectBycommdityinfo(String id) {
	
	
	return operatorCommodityDao.selectBycommdityinfo(id);
	
	
}*/




@Transactional
public ProvideCommodity  addcommdity(String commdittyName){
	ProvideCommodity  provideCommodity=new ProvideCommodity();
	provideCommodity.setCommodityName(commdittyName);
	return   provideCommodityRepository.save(provideCommodity);
	
}
/** 
 * 去掉重复字符串 
 * @param str 
 * @return String  
 * */  
public static  String removeSameString(String str){    
    Set<String> mLinkedSet = new LinkedHashSet<String>();    
    String[] strArray = str.split(",");    
    StringBuffer sb = new StringBuffer();    
    for (int i = 0; i < strArray.length; i++)    
    {    
        if (!mLinkedSet.contains(strArray[i]))    
        {    
            mLinkedSet.add(strArray[i]);    
            sb.append(strArray[i] + " ");    
        }else{  
  //          System.out.println("重复字符:"+strArray[i]);  
        }    
    }    
//    System.out.println(mLinkedSet);    
    return sb.toString().substring(0, sb.toString().length() - 1);    
}    

	
	@Transactional
	public ReturnResult  reviewProduct(String id,String userid){
		ReturnResult returnResult=new ReturnResult();
		ProvideCommodity provideCommodity=	provideCommodityRepository.findOne(id);
		if(provideCommodity!=null){
			provideCommodity.setCommodityState(2);
			provideCommodity.setAuditOpinion("审核通过");
			provideCommodity.setRefuseTime(new Date());
			provideCommodity.setReleaseTime(new Date());
			provideCommodityRepository.save(provideCommodity);
			String servercity="";
			String servercity1="";
			if(provideCommodity.getProviderBusiness()!=null){
				//isTerritoryRestriction;//是否有地域限制 1:有 2:没有
				if(provideCommodity.getIsTerritoryRestriction()!=null){
						 List<ProvideCommodity>  comms=provideCommodityRepository.selectByCommodity(provideCommodity.getProviderBusiness().getId());
							 for (ProvideCommodity provideCommodity2 : comms) {
								if(provideCommodity2.getIsTerritoryRestriction()!=null){
									if(provideCommodity2.getIsTerritoryRestriction().equals("2")){
		    	     					 List<OperatorCity> ops=	operatorCityRepository.findAll();
		    	     					 if(ops.size()>0){
		    	     						 for (OperatorCity operatorCity : ops) {
		    	     							 List<ProvideCity>  provideCity1=provideCityRepository.findByCode(operatorCity.getCityId());
		    	     							 if(provideCity1.size()>0){
		    	     								 servercity1+=provideCity1.get(0).getName()+",";
		    	     							 }
		    	     						 }
		    	     					 }
									}else if(provideCommodity2.getIsTerritoryRestriction().equals("1")){
										List<ProvideCommodityServiceRange>  pcs=provideCommodityServiceRangeRepository.selectByServerArea(provideCommodity.getId());
		    	     					 if(pcs.size()>0){
		    	     						 for (ProvideCommodityServiceRange provideCommodityServiceRange : pcs) {
		    	     							 ProvideCity  city=	 provideCityRepository.findOne(provideCommodityServiceRange.getCity().getId());
		    	     							 servercity+=city.getName()+",";
											}
		    	     					 }
									}
									
								}
						}
					
				}
				String c=removeSameString(servercity);
				String c1=removeSameString(servercity1);
				String c2="";
				if(!c1.equals("")){
					c2=c1;
				}else{
					c2=c;
				}
				ProviderBusiness providerBusiness=providerBusinessRepository.findOne(provideCommodity.getProviderBusiness().getId());
				if(providerBusiness!=null){
					providerBusiness.setServiceAreas(c2);
					providerBusinessRepository.save(providerBusiness);
				}
			}
			if(provideCommodity.getProviderBusiness()!=null){
				MessageType messageType=new MessageType();
				messageType.setSourceid(id);
				messageType.setCreatedate(new Date());
				messageType.setDecribestr("您有一个【"+provideCommodity.getCommodityName()+"】商品审核已通过");
				messageType.setIsread(0);
				messageType.setType(2);
				messageType.setBusinessid(provideCommodity.getProviderBusiness().getId());
				messageTypeRepository.save(messageType);
			}
			OperatorRefuseRecord  operatorRefuseRecord=new OperatorRefuseRecord();
			operatorRefuseRecord.setAttributId(id);
			operatorRefuseRecord.setRefuseTime(new Date());
			operatorRefuseRecord.setStatus(1);
			operatorRefuseRecord.setOpchannel(1);
			OperatorUser operatorUser=operatorUserRepository.findOne(userid);
			if(operatorUser!=null){
				operatorRefuseRecord.setUseraccountforcord(operatorUser.getUsername()+"已审批");
			}
			operatorRefuseRecordRepository.save(operatorRefuseRecord);
			returnResult.setKey("success");
			returnResult.setValue("审核通过");
		}else{
			returnResult.setKey("error");
			returnResult.setValue("审核失败");
		}
		return  returnResult;
	}
	
	public   List<OperatorRefuselist>   reasonDropdown(){
		
		List<OperatorRefuselist> list=	operatorRefuselistRepository.selectBycommrefuse();
		if(list.size()>0){
			return  list;
		}
		return  null;
	}
	public   List<OperatorRefuselist>   reasonxiajia(){
		
		List<OperatorRefuselist> list=	operatorRefuselistRepository.selectBycommrefusexj();
		if(list.size()>0){
			return  list;
		}
		return  null;
	}
	
	@Transactional
	public  ReturnResult  refuseCommdity(String id,String refuseName,String content,String userid){
		ReturnResult returnResult =new ReturnResult();
		ProvideCommodity provideCommodity=	provideCommodityRepository.findOne(id);
		if(provideCommodity!=null){
			OperatorRefuseRecord  operatorRefuseRecord=new OperatorRefuseRecord();
			operatorRefuseRecord.setAttributId(id);
			operatorRefuseRecord.setContent(content);
			operatorRefuseRecord.setReasonName(refuseName);
			operatorRefuseRecord.setRefuseTime(new Date());
			operatorRefuseRecord.setOpchannel(1);
			operatorRefuseRecord.setStatus(2);
			OperatorUser operatorUser=operatorUserRepository.findOne(userid);
			if(operatorUser!=null){
				operatorRefuseRecord.setUseraccountforcord(operatorUser.getUsername()+"拒绝");
			}
			operatorRefuseRecordRepository.save(operatorRefuseRecord);
			if(provideCommodity.getProviderBusiness()!=null){
				MessageType messageType=new MessageType();
				messageType.setSourceid(id);
				messageType.setCreatedate(new Date());
				messageType.setDecribestr("您有一个【"+provideCommodity.getCommodityName()+"】商品审核未通过");
				messageType.setIsread(0);
				messageType.setType(2);
				messageType.setBusinessid(provideCommodity.getProviderBusiness().getId());
				messageTypeRepository.save(messageType);
			}
			provideCommodity.setAuditOpinion(refuseName);
			provideCommodity.setReasoncontent(content);
			provideCommodity.setRefuseTime(new Date());
			provideCommodity.setCommodityState(3);
			provideCommodity.setReadState(2);
			provideCommodityRepository.save(provideCommodity);
			returnResult.setKey("success");
			returnResult.setValue("拒绝成功");
		}else{
			returnResult.setKey("error");
			returnResult.setValue("拒绝失败");
		}
		return  returnResult;
	}
	@Transactional
	public  ReturnResult  shelvesCommdity(String id,String refuseName,String content,String userid){
		ReturnResult returnResult =new ReturnResult();
		ProvideCommodity provideCommodity=	provideCommodityRepository.findOne(id);
		if(provideCommodity!=null){
			OperatorRefuseRecord  operatorRefuseRecord=new OperatorRefuseRecord();
			operatorRefuseRecord.setAttributId(id);
			operatorRefuseRecord.setContent(content);
			operatorRefuseRecord.setReasonName(refuseName);
			operatorRefuseRecord.setRefuseTime(new Date());
			operatorRefuseRecord.setOpchannel(1);
			operatorRefuseRecord.setStatus(3);
			OperatorUser operatorUser=operatorUserRepository.findOne(userid);
			if(operatorUser!=null){
				operatorRefuseRecord.setUseraccountforcord(operatorUser.getUsername()+"下架");
			}
			operatorRefuseRecordRepository.save(operatorRefuseRecord);
			provideCommodity.setAuditOpinion(refuseName);
			provideCommodity.setCommodityState(5);
			provideCommodity.setReadState(2);
			provideCommodity.setReasoncontent(content);
			provideCommodity.setRefuseTime(new Date());
			provideCommodityRepository.save(provideCommodity);
			if(provideCommodity.getProviderBusiness()!=null){
				MessageType messageType=new MessageType();
				messageType.setSourceid(id);
				messageType.setCreatedate(new Date());
				messageType.setDecribestr("您有一个【"+provideCommodity.getCommodityName()+"】商品审核已违规");
				messageType.setIsread(0);
				messageType.setType(2);
				messageType.setBusinessid(provideCommodity.getProviderBusiness().getId());
				messageTypeRepository.save(messageType);
			}
			String servercity="";
			String servercity1="";
			if(provideCommodity.getProviderBusiness()!=null){
				//isTerritoryRestriction;//是否有地域限制 1:有 2:没有
				if(provideCommodity.getIsTerritoryRestriction()!=null){
						 List<ProvideCommodity>  comms=provideCommodityRepository.selectByCommodity(provideCommodity.getProviderBusiness().getId());
							 for (ProvideCommodity provideCommodity2 : comms) {
								if(provideCommodity2.getIsTerritoryRestriction()!=null){
									if(provideCommodity2.getIsTerritoryRestriction().equals("2")){
		    	     					 List<OperatorCity> ops=	operatorCityRepository.findAll();
		    	     					 if(ops.size()>0){
		    	     						 for (OperatorCity operatorCity : ops) {
		    	     							 List<ProvideCity>  provideCity1=provideCityRepository.findByCode(operatorCity.getCityId());
		    	     							 if(provideCity1.size()>0){
		    	     								 servercity1+=provideCity1.get(0).getName()+",";
		    	     							 }
		    	     						 }
		    	     					 }
									}else if(provideCommodity2.getIsTerritoryRestriction().equals("1")){
										List<ProvideCommodityServiceRange>  pcs=provideCommodityServiceRangeRepository.selectByServerArea(provideCommodity.getId());
		    	     					 if(pcs.size()>0){
		    	     						 for (ProvideCommodityServiceRange provideCommodityServiceRange : pcs) {
		    	     							 ProvideCity  city=	 provideCityRepository.findOne(provideCommodityServiceRange.getCity().getId());
		    	     							 servercity+=city.getName()+",";
											}
		    	     					 }
									}
									
								}
						}
					
				}
				String c=removeSameString(servercity);
				String c1=removeSameString(servercity1);
				String c2="";
				if(!c1.equals("")){
					c2=c1;
				}else{
					c2=c;
				}
				ProviderBusiness providerBusiness=providerBusinessRepository.findOne(provideCommodity.getProviderBusiness().getId());
				if(providerBusiness!=null){
					providerBusiness.setServiceAreas(c2);
					providerBusinessRepository.save(providerBusiness);
				}
			}
			returnResult.setKey("success");
			returnResult.setValue("下架成功");
		}else{
			returnResult.setKey("error");
			returnResult.setValue("下架失败");
		}
		return  returnResult;
	}
	/**
	 * 
	    * @Title: selectByCommodityStateAndPerviderDictionaryId  
	    * @Description: 根据  商品单位(PerviderDictionaryId) 查询 商品状态不为6  的商品 
	    * @param @param perviderDictionaryId
	    * @param @return      
	    * @return List<ProvideCommodity>      
	    * @throws
	 */
	public List<ProvideCommodity> selectByCommodityStateAndPerviderDictionaryId(String perviderDictionaryId) {
		return provideCommodityRepository.selectByCommodityStateAndPerviderDictionaryId(perviderDictionaryId);
	}
	
	
	/**
	 * 商品id str
	 * @param ids
	 * @return
	 */
	
	@Transactional
	public  ReturnResult  batchshelvesComdity(String ids,String reasonName,String  content,String userid){
		ReturnResult returnResult=new ReturnResult();
		String[] str=StringUtil.StrList(ids);
		String id="";
		for (int i = 0; i < str.length; i++) {
			id=str[i];
			ProvideCommodity provideCommodity=	provideCommodityRepository.findOne(id);
			if(provideCommodity!=null){
					OperatorRefuseRecord  operatorRefuseRecord=new OperatorRefuseRecord();
					operatorRefuseRecord.setAttributId(id);
					operatorRefuseRecord.setContent(content);
					operatorRefuseRecord.setReasonName(reasonName);
					operatorRefuseRecord.setRefuseTime(new Date());
					operatorRefuseRecord.setOpchannel(1);
					operatorRefuseRecord.setStatus(3);
					OperatorUser operatorUser=operatorUserRepository.findOne(userid);
					if(operatorUser!=null){
						operatorRefuseRecord.setUseraccountforcord(operatorUser.getUsername()+"下架");
					}
					operatorRefuseRecordRepository.save(operatorRefuseRecord);
				provideCommodity.setAuditOpinion(reasonName);
				provideCommodity.setCommodityState(5);
				provideCommodity.setReadState(2);
				provideCommodity.setReasoncontent(content);
				provideCommodity.setRefuseTime(new Date());
				provideCommodityRepository.save(provideCommodity);
				if(provideCommodity.getProviderBusiness()!=null){
					MessageType messageType=new MessageType();
					messageType.setSourceid(id);
					messageType.setCreatedate(new Date());
					messageType.setDecribestr("您有一个【"+provideCommodity.getCommodityName()+"】商品审核已违规");
					messageType.setIsread(0);
					messageType.setType(2);
					messageType.setBusinessid(provideCommodity.getProviderBusiness().getId());
					messageTypeRepository.save(messageType);
				}
				String servercity="";
				String servercity1="";
				if(provideCommodity.getProviderBusiness()!=null){
					//isTerritoryRestriction;//是否有地域限制 1:有 2:没有
					if(provideCommodity.getIsTerritoryRestriction()!=null){
							 List<ProvideCommodity>  comms=provideCommodityRepository.selectByCommodity(provideCommodity.getProviderBusiness().getId());
								 for (ProvideCommodity provideCommodity2 : comms) {
									if(provideCommodity2.getIsTerritoryRestriction()!=null){
										if(provideCommodity2.getIsTerritoryRestriction().equals("2")){
			    	     					 List<OperatorCity> ops=	operatorCityRepository.findAll();
			    	     					 if(ops.size()>0){
			    	     						 for (OperatorCity operatorCity : ops) {
			    	     							 List<ProvideCity>  provideCity1=provideCityRepository.findByCode(operatorCity.getCityId());
			    	     							 if(provideCity1.size()>0){
			    	     								 servercity1+=provideCity1.get(0).getName()+",";
			    	     							 }
			    	     						 }
			    	     					 }
										}else if(provideCommodity2.getIsTerritoryRestriction().equals("1")){
											List<ProvideCommodityServiceRange>  pcs=provideCommodityServiceRangeRepository.selectByServerArea(provideCommodity.getId());
			    	     					 if(pcs.size()>0){
			    	     						 for (ProvideCommodityServiceRange provideCommodityServiceRange : pcs) {
			    	     							 ProvideCity  city=	 provideCityRepository.findOne(provideCommodityServiceRange.getCity().getId());
			    	     							 servercity+=city.getName()+",";
												}
			    	     					 }
										}
										
									}
							}
						
					}
					String c=removeSameString(servercity);
					String c1=removeSameString(servercity1);
					String c2="";
					if(!c1.equals("")){
						c2=c1;
					}else{
						c2=c;
					}
					ProviderBusiness providerBusiness=providerBusinessRepository.findOne(provideCommodity.getProviderBusiness().getId());
					if(providerBusiness!=null){
						providerBusiness.setServiceAreas(c2);
						providerBusinessRepository.save(providerBusiness);
					}
				}
			 }
		
		}
		returnResult.setKey("success");
		returnResult.setValue("下架成功");
		return returnResult;
	}


    public ReturnResult getAllRoundingCommsNum() {
		ReturnResult returnResult = new ReturnResult();
		try {
			Query nativeQuery = entityManager.createNativeQuery("select  count(1) from t_provide_commodity where commodity_state=2");
			List resultList = nativeQuery.getResultList();
			long num = Long.parseLong(resultList.get(0) + "");
			returnResult.setKey("success");
			returnResult.setValue(num);
		} catch (Exception e) {
			returnResult.setKey("error");
		}
		return returnResult;
	}
}
